//
//  XYJMineHeaderView.m
//  徙游记-01
//
//  Created by hcios on 2017/7/14.
//  Copyright © 2017年 鹿林. All rights reserved.
//

#import "XYJMineHeaderView.h"
#import "SZKImagePickerVC.h"
#import "UIImageView+WebCache.h"
#import "UIImageView+LBBlurredImage.h"


@implementation XYJMineHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupSubViews];
    }
    return self;
}


-(void)setupSubViews{
    
    //1.背景图片
    _bgImageView = [[UIImageView alloc] initWithFrame:self.bounds];
    [_bgImageView setImageToBlur:[UIImage imageNamed:@"goldengate"] blurRadius:20 completionBlock:nil];
    _bgImageView.userInteractionEnabled = YES;
    [self addSubview:_bgImageView];
    
    //2.头像
    _headImageView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 80) / 2, (self.bounds.size.height - 80) / 2, 80, 80)];
    _headImageView.layer.cornerRadius = 40;
    _headImageView.layer.masksToBounds = YES;
    _headImageView.userInteractionEnabled = YES;
    [_headImageView sd_setImageWithURL:[NSURL URLWithString:@"http://a.chanyouji.cn/705176/1484967909.jpg"] placeholderImage:nil];
    [_bgImageView addSubview:_headImageView];
    
    
    //创建点击手势
    UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickHead)];
    [_headImageView addGestureRecognizer:ges];
    
    
    
    //3.昵称
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_headImageView.frame) + 20, SCREEN_WIDTH, 30)];
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    _nameLabel.textColor = [UIColor whiteColor];
    _nameLabel.font = [UIFont fontWithName:FONT_NAME_LTH size:19];
    _nameLabel.text = @"镜子背后的灰尘";
    [_bgImageView addSubview:_nameLabel];
    
    
    _settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_settingBtn setFrame:CGRectMake(15, 33, 24, 24)];
    [_settingBtn setImage:[UIImage imageNamed:@"btn_my_setting"] forState:UIControlStateNormal];
    [_settingBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [_bgImageView addSubview:_settingBtn];
    
    
    _erWeiMaBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_erWeiMaBtn setFrame:CGRectMake(SCREEN_WIDTH - 40, 33, 25, 25)];
    [_erWeiMaBtn setImage:[UIImage imageNamed:@"btn_qrcode"] forState:UIControlStateNormal];
    [_erWeiMaBtn addTarget:self action:@selector(clickMa) forControlEvents:UIControlEventTouchUpInside];
    [_bgImageView addSubview:_erWeiMaBtn];
}


-(void)clickHead{
    if (self.delegate && [self.delegate respondsToSelector:@selector(changeImage)]) {
        [self.delegate changeImage];
    }
}


-(void)click{
    if (self.delegate && [self.delegate respondsToSelector:@selector(setting)]) {
        [self.delegate setting];
    }
}


-(void)clickMa{
    if (self.delegate && [self.delegate respondsToSelector:@selector(erWeiMa)]) {
        [self.delegate erWeiMa];
    }
}

@end
